package com.xk._01基础篇._11哈希表.model;

import java.util.Objects;

/**
 * @description:
 * @author: xu
 * @date: 2022/9/27 11:27
 */
public class Person implements Comparable<Person>{
    private String name;
    private int age;
    private float height;

    public Person(String name, int age, float height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    // 用来比较两个对象是否相等(IDEA自动生成)
    @Override
    public boolean equals(Object o) {
        // 内存地址
        if (this == o) return true;
        if (!(o instanceof Person)) return false;
        Person person = (Person) o;
        return age == person.age && Float.compare(person.height, height) == 0 && Objects.equals(name, person.name);
    }

    // IDEA 自动生成的hashCode()
    @Override
    public int hashCode() {
        return Objects.hash(name, age, height);
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }

    @Override
    public int compareTo(Person o) {
        return age - o.age;
    }

    /*@Override
    public int hashCode() {
        int hashCode = (name != null ? name.hashCode() : 0);
        hashCode = hashCode * 31 + Integer.hashCode(age);
        hashCode = hashCode * 31 + Float.hashCode(height);
        return hashCode;
    }*/
}
